package cn.lingyangwl.agile.pay.client.assembly;

import cn.lingyangwl.agile.pay.client.constants.OrderStatus;
import cn.lingyangwl.framework.tool.core.StringUtils;
import cn.lingyangwl.framework.tool.core.exception.BizException;
import cn.lingyangwl.agile.pay.model.entity.PayOrder;
import org.mapstruct.Mapper;

/**
 * @author shenguangyang
 */
@Mapper(componentModel = "spring")
public interface ProductOrderAssembly {
    default OrderStatus toOrderStatus(String status) {
        if (StringUtils.equals(PayOrder.STATE_ING, status)) {
            return OrderStatus.NO_PAY;
        } else if (StringUtils.equals(PayOrder.STATE_REFUND, status)) {
            return OrderStatus.REFUND_SUCCESS;
        } else if (StringUtils.equals(PayOrder.STATE_CANCEL, status)) {
            return OrderStatus.CANCEL;
        } else if (StringUtils.equals(PayOrder.STATE_CLOSED, status)) {
            return OrderStatus.CLOSED;
        } else {
            throw new BizException("未知退款状态");
        }
    }
}
